// mock.js
import Mock from 'mockjs';

// 示例数据
const data = Mock.mock({
    //   'list|1-10': [{
    //     'id|+1': 1,
    //     'name': '@cname',
    //     'age|20-30': 1,
    //   }]
    'list|4': [{
        'id|+1': 1,
        'name': '@cname',
        "number|1-36": 2,
        'time': '@datetime',
    }]
}).list;

// 模拟GET请求
Mock.mock('/api/data', 'get', {
    code: 200,
    data: data,
    message: 'success'
});

// 模拟POST请求
Mock.mock('/api/users', 'post', (options) => {
    const newUser = JSON.parse(options.body);
    console.log(options.body);
    newUser.id = users.length + 1;
    users.push(newUser);
    return {
        code: 200,
        data: newUser,
        message: 'User added successfully'
    };
});